package com.singleton;

import java.io.Serializable;

/**如果通过序列化、反序列化也会破坏单例，我们可以通过重写readResolve()方法，但这样做其实底层还是会先实例化对象，然后再调用readResolve()方法。
 * 有没有办法不实例化？就是通过枚举
 * @author zhangsulei
 *
 */
public class SeriableSingletonDemo implements Serializable {

	/**
	 *
	 */
	private static final long serialVersionUID = -2339683825939779125L;
	private static SeriableSingletonDemo uniqueInstance = new SeriableSingletonDemo();

	// other useful instance variables here

	private SeriableSingletonDemo() {
	}

	public static synchronized SeriableSingletonDemo getInstance() {
		return uniqueInstance;
	}

	private Object readResolve(){
		return uniqueInstance;
	}

}
